package com.rdc.qingkou.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.rdc.qingkou.Application.MyApplication;
import com.rdc.qingkou.R;
import com.rdc.qingkou.contract.LogoutContract;
import com.rdc.qingkou.entity.Result;
import com.rdc.qingkou.presenter.LogoutPresenter;
import com.rdc.qingkou.utils.ACache;
import com.rdc.qingkou.utils.DirectedLoginUtil;

public class ExitApplicationDialogActivity extends AppCompatActivity implements LogoutContract.IView{

    private LogoutPresenter logoutPresenter;
    private ACache aCache;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        aCache = ACache.get(this);
        MyApplication.addActivity(this);
        logoutPresenter = new LogoutPresenter(this);
        setContentView(R.layout.activity_exit_application_dialog);

        findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        findViewById(R.id.tv_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                logoutPresenter.logout();
                new Thread() {
                    @Override
                    public void run() {
                        super.run();
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        aCache.clear();
                        //MyApplication.setCookie(null);
                        DirectedLoginUtil.setAccount(null,null);
                        MyApplication.exit();
                    }
                }.start();

            }
        });
    }
    @Override
    public void logout(Result result) {

        Log.d("ExitAppActivity",result.getResult());
    }

    @Override
    public void showInfo(String info) {
        Log.d("ExitAppActivity","ERROR : " + info);
    }
}
